package ststat.project2;

import java.awt.Color;
import java.util.ArrayList;
import javax.swing.JFrame;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartFrame;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.plot.CategoryPlot;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.data.category.DefaultCategoryDataset;

public class Driver {

    /**
     * @param args
     */
    public static void main(String[] args) {
        ArrayList<DataPoint> data = Calculator.hypergeometricDistribution(1, 10, 50, 10, 20);

        for (int i = 0; i < data.size(); i++) {
            System.out.println(data.get(i).getX() + " " + data.get(i).getValue());
        }

        System.out.println("Total: " + Calculator.total(data));

        DefaultCategoryDataset dataset = new DefaultCategoryDataset();
        for(int i = 0; i<data.size(); i++){
            dataset.setValue(data.get(i).getValue(),"Probability", Integer.toString(data.get(i).getX()));
        }
        
        JFreeChart chart = ChartFactory.createBarChart("Hypergeometric", "X", "Probability", dataset, PlotOrientation.VERTICAL, false, false, false);
        CategoryPlot plot = chart.getCategoryPlot();
        plot.setRangeGridlinePaint(Color.BLACK);
        ChartFrame frame = new ChartFrame("Bar Graph",chart);
        frame.setSize(450,350);
        frame.setVisible(true);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        
        ArrayList<DataPoint> sim1 = Calculator.hypergeometricDistributionN(1, 50,1,20,5);
        DefaultCategoryDataset dataset2 = new DefaultCategoryDataset();
        for(int i=0; i<sim1.size(); i++)
        {
           dataset2.setValue(sim1.get(i).getValue(),"Probability", Integer.toString(sim1.get(i).getX()));
        }
        
        JFreeChart chart2 = ChartFactory.createBarChart("Simulation 1", "X", "Probability", dataset2, PlotOrientation.VERTICAL, false, false, false);
        //plot = chart2.getCategoryPlot();
        
        ChartFrame frame2 = new ChartFrame("Simulation 1", chart2);
        frame2.setSize(450,350);
        frame2.setVisible(true);
        frame2.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        
    }
}
